package com.romotc.qqrobot.webqq.qqInterfaceCatching;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;

import com.romotc.qqrobot.bean.QQLogedin;
import com.romotc.scache.RequestSpy;
import com.romotc.scache.WebConnection;
/**
 * 客服人员工号专用 获取用户头像
 * @author Administrator
 *
 */
public class Getface_ForMemCustService_Catching extends
		QQUrlCatchingInterface {

	public static void main(String[] args) {
		System.out.println(File.separator);
	}
	@Override
	public boolean hackRequest(RequestSpy requestSpy) {
		if(checkChatchingCondition(requestSpy)) {
			
			File file = new File("web" + File.separator + "images" + File.separator + "defaultFace.jpeg");
			byte[] bytes = new byte[(int) file.length()];
			DataInputStream input = null;
			try {
				input = new DataInputStream(new FileInputStream(file));
				input.readFully(bytes);
				requestSpy.make_headers(200, "image/jpeg", null, null, bytes.length,
						System.currentTimeMillis() + 10000000, 0, null);
				requestSpy.send_headers();
				requestSpy.sendBytes(bytes);
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (input != null) {
					try {
						input.close();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
			
			return false;
		}

		return true;
	
	}

	@Override
	public boolean modifyResponse(WebConnection wc, RequestSpy rqSpy)
			throws IOException {
		// TODO Auto-generated method stub
		return false;
	}

	
	public boolean checkChatchingCondition(RequestSpy requestSpy) {
		QQLogedin curQQ = QQLogedin.getCurQqLogedIn(requestSpy);
		if(curQQ != null && curQQ.getCsId() > 0) {
			//是虚拟号码
			return true;
		}
		return false;
	}
}
